package co.sainsoft.turningsoft.demo.dao.impl;

import co.sainsoft.turningsoft.demo.dao.PerfilesDAO;
import co.sainsoft.turningsoft.demo.model.Perfiles;
import co.sainsoft.turningsoft.demo.util.HibernateUtil;
import java.util.List;
import org.hibernate.Session;

public class PerfilesDAOImpl implements PerfilesDAO {

    @Override
    public void actualizar(Perfiles perfil) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            session.update(perfil);
            session.beginTransaction().commit();
            session.close();
        } catch (Exception e) {
            System.out.println("Error al actualizar el perfil: " + e.getMessage());
            session.beginTransaction().rollback();
            session.close();
        }
    }

    @Override
    public Perfiles buscarPerfil(String codPerfil) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        return (Perfiles) session.load(Perfiles.class, codPerfil);
    }

    @Override
    public List<Perfiles> buscarTodos() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        return session.createQuery("from Perfil").list();
    }
    
}
